package BandB.Tool.GPhoneManager.Widget.Wifi;

import android.app.Service;
import android.content.Intent;
import android.net.wifi.WifiManager;
import android.os.IBinder;
import android.util.Log;

public class WifiSettingServiceOnOff extends Service {
	private String TAG = "WifiOnOff2Widget";
	private WifiManager wifiManager;
	// private boolean isTurnOnSuccess;
	// private boolean isTurnOffSuccess;
	// private int userOption;
	public static final int OPTION_TURN_ON_WIFI = 0;
	public static final int OPTION_TURN_OFF_WIFI = 1;
	public static final String KEY_USER_OPTION = "UserOption";

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onCreate() {
		Log.i(TAG, "setting service oncreate onoff2");
		wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
		super.onCreate();

	}

	@Override
	public void onStart(Intent intent, int startId) {
		Log.i(TAG, "setting service onStart onoff2");
		super.onStart(intent, startId);
		if (!wifiManager.isWifiEnabled()) {
			// userOption = OPTION_TURN_ON_WIFI;
			// isTurnOnSuccess = false;
			wifiManager.setWifiEnabled(true);
			Log.w(TAG, "Has turned on wifi");
			wifiManager.reconnect();
			wifiManager.reassociate();

		} else {
			// userOption = OPTION_TURN_OFF_WIFI;
			// isTurnOffSuccess = false;
			wifiManager.setWifiEnabled(false);
			Log.w(TAG, "Has shut down wifi");
		}

	}

}
